package com.gy.controller;

import com.gy.pojo.QuYu;
import com.gy.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class QuYuController {
    @Autowired
    BaoXiuService baoXiuService;
    @Autowired
    LeiXingService leiXingService;
    @Autowired
    NoticeService noticeService;
    @Autowired
    UserService userService;
    @Autowired
    QuYuService quYuService;

    //查看区域
    @RequestMapping("/worker/selectqy")
    public String selectqu(Model model){
        List<QuYu> quYus = quYuService.selectQY();
        model.addAttribute("quyu",quYus);

        return "worker/quyulist";
    }

    //根据Qid删除区域
    @RequestMapping("/worker/deleteqy/{Qid}")
    public String deleteqy(@PathVariable("Qid") int Qid){
        quYuService.deleteQY(Qid);
        return "redirect:/worker/selectqy";
    }

    //增加区域
        //来到增加区域页面
    @RequestMapping("/worker/addqy")
    public String comeadd(){


        return "worker/addquyu";
    }

        //增加区域
    @PostMapping("/worker/addquyu")
    public String addquyu(String Qname,String Qlou,int Qfang){
        //取出当前最大值
        int Qid = quYuService.maxQid()+1;
        quYuService.addQY(new QuYu(Qid,Qname,Qlou,Qfang));


        return "redirect:/worker/selectqy";
    }







}
